<template>
  <div class="GSupervisionPolice">
    <filterPanel filterName="GSupervisionPoliceFilter" filterTitle="监管民警查询" :filterList="filterData"
                 @filterChange="filterChange"></filterPanel>
    <tablePanel tableName="GSupervisionPoliceTable" :tableLoading="loading" tableTitle="监管民警列表" :tableList="tableList"
                :tableData="tableData" :total="total" :currentPage="form.page_start" :pageSize="form.page_size"
                @sizeChange="sizeChange" @pageChange="pageChange" @tableClick="tableClick">
      <zy-button @click="add" type="primary">新增</zy-button>
      <zy-button  @click="exportExcel">导出列表</zy-button>
    </tablePanel>
  </div>
</template>

<script>
	import {mapGetters} from "vuex";

	export default {
		name: "GSupervisionPolice",
		props: {},
		data() {
			return {
				currentPath: '/police_manage',
				filterData: [
					{
						title: '民警姓名',
						name: 'name',
						type: 'input',
						value: '',
						maxlength: '20',
						isShow: true,
						isSelected: true
					},
					{
						title: '联系电话',
						name: 'mobile',
						type: 'input',
						value: '',
						maxlength: '20',
						isShow: true,
						isSelected: true
					},
					{
						title: '警号',
						name: 'cardno',
						type: 'input',
						value: '',
						maxlength: '20',
						isShow: true,
						isSelected: true
					},
					{
						title: '辖区名称',
						name: 'regulated_names',
						type: 'input',
						value: '',
						maxlength: '20',
						isShow: true,
						isSelected: true
					},
					{
						title: '创建时间',
						name: 'registration_date',
						type: 'date',
						value: [],
						isShow: true,
						isSelected: true
					},
				],
				form: {
					name: '',
					mobile: '',
					cardno: '',
					addr: '',
					registration_date: [],
					page_start: 1,
					page_size: 10
				},
				loading: false,
				tableList: [
					{
						title: '民警姓名',
						width: 120,
						name: 'name',
						isShow: true,
						isSelected: true
					},
					{
						title: '联系电话',
						width: 180,
						name: 'mobile',
						isShow: true,
						isSelected: true
					},
					{
						title: '警号',
						width: 140,
						name: 'cardno',
						isShow: true,
						isSelected: true
					},
					{
						title: '辖区',
						width: 160,
						name: 'regulated_names',
						isShow: true,
						isSelected: true
					},
					{
						title: '物流企业数量',
						width: 120,
						name: 'company_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '合作站点数量',
						width: 120,
						name: 'cooper_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '创建时间',
						width: 180,
						name: 'ctime',
						isShow: true,
						isSelected: true
					},
					{
						title: '操作',
						width: 200,
						name: 'handler',
						fixed: 'right',
						btns: [
							{
								type: 'detail',
								name: '详情'
							},
							{
								type: 'modify',
								name: '修改'
							},
							{
								type: 'delete',
								name: '删除',
								btnType: 'danger'
							},
						],
						isSelected: true
					}
				],
				tableData: [],
				total: 0,
				download_url: ''
			};
		},
		computed: {
			postData() {
				let data = {
					name: this.form.name,
					mobile: this.form.mobile,
					cardno: this.form.cardno,
					regulated_names: this.form.regulated_names,
					pagination: {
						page_start: this.form.page_start,
						page_size: this.form.page_size
					}
				};
				if (this.form.registration_date && this.form.registration_date.length > 0) {
					data.start_created_time = this.form.registration_date[0] / 1000;
					data.end_created_time = this.form.registration_date[1] / 1000;
				}
				return data;
			},
			...mapGetters(['authority']),
			isAdd() {
				return this.authority[this.currentPath] && this.authority[this.currentPath].i;
			},
			isLook() {
				return this.authority[this.currentPath] && this.authority[this.currentPath].m;
			},
			isModify() {
				return this.authority[this.currentPath] && this.authority[this.currentPath].m;
			},
			isDel() {
				return this.authority[this.currentPath] && this.authority[this.currentPath].d;
			},
		},
		watch: {
			$route: {
				handler() {
					let {isRefresh, path} = this.$route.params;
					if (this.currentPath == path && isRefresh) this.getData();
				},
				deep: true
			}
    },
		components: {},
		methods: {
			//导出
			exportExcel() {
				this.$import_excal(this.download_url || "");
			},
			// 新增
			add() {
				this.$toRoutePath({
					path: "/police_manage/police_manage_detail",
					edit: true,
					query: {type: 'add'}
				});
			},
			sizeChange(val) {
				this.form.page_size = val;
				this.getData()
			},
			pageChange(val) {
				this.form.page_start = val;
				this.getData()
			},
			filterChange(data) {
				this.form = {...this.form, ...data};
				this.getData();
			},
			getData() {
				this.loading = true;
				this.tableData = [];
				this.$axios.post(this.$api.listContactPolice, {...this.postData}).then(res => {
					let {code, msg, data} = res;
					this.loading = false;
					if (code == 200) {
						this.tableData = data.list.filter(item => {
							item.detail = this.isLook || true;
							item.modify = this.isModify || true;
							item.delete = this.isDel || true;
							return item;
						});
						this.download_url = data.download_url || ''
						this.total = data.pagination.total_count || 0;
					} else {
						this.total = 0
						this.tableData = [];
					}
				}).catch(ret => {
					this.$message.error(ret.msg || '服务繁忙，请稍后再试');
				});
			},
			tableClick(data, type) {
				let {id} = data;
				switch (type) {
					case 'detail':
					case 'modify':
						this.$toRoutePath({
							path: "/police_manage/police_manage_detail",
							edit: true,
							query: {type, id}
						});
						break;
					case 'delete':
						this.deleted(id);
						break;
				}
			},
			// 删除
			deleted(id) {
				this.$confirm("此操作将永久删除该信息, 是否继续?", "提示", {
					confirmButtonText: "确定",
					cancelButtonText: "取消",
					type: "warning",
					customClass: 'message',
				}).then(() => {
					this.$axios.post(this.$api.makeContactPolice, {
						id: id,
						name: '',
						mobile: '',
						cardno: '',
						addr: '',
						state: 0
					}).then(res => {
						let {code, msg} = res;
						if (code === 200) {
							this.$message.success('删除成功')
							this.getData();
						} else {
							this.$message.error(msg)
						}
					})
				}).catch(() => {
					this.$message.info("已取消删除");
				});
			},
		},
		mounted() {
			this.getData();
		},
		created() {
		}
	}
</script>

<style scoped lang="less" src="@/style/government/personnelManage/supervisionPoliceList/index.less">

</style>
